/**
 * @Author：ming
 * @Date：2023/10/5 11:40 PM
 * @Filename：Lc121
 */

/**
 * @author ming
 */
public class Lc121 {
    public int maxProfit(int[] prices) {
        int max =0;
        int profit =0;
        int price = prices[0];
        for (int i = 0; i < prices.length; i++) {
            if(prices[i]>price){
                profit = prices[i]-price;
                max = Math.max(max,profit);
            }else if(prices[i]<price){
                price =prices[i];
            }
        }

        return max;
    }
}
